/**
  ******************************************************************************
  * @author     Chris
  * @since      2024/6/10 12:38
  *
  * @file       hd_oled_protocol_i2c.c
  * @brief      OLED I2C Communication Protocol Hardware Driver.
  *
  * @note       This file contains the I2C Communication Protocol hardware
  *             driver for the OLED.
  *
  * @warning    None.
  ******************************************************************************
  * Change Logs:
  *   Date           Author       Notes
  *   2024-06-10     Chris        the first version
  *
  ******************************************************************************
  */

#include "stdlib.h"
#include "hd_oled_protocol_i2c.h"


/**
 * I2C GPIO init
 *
 * @param super
 */
static void OLEDProtocolI2C_init_(const OLEDProtocol *super) {
    /**
     *  TODO I2C can init in here or main() function
     *  It's not suitable to init I2C in here, when we have more than one i2c device,
     *  because it can be repeatable. It's better to init I2C in main() function.
     */
    // struct OLEDProtocolI2C *this = (struct OLEDProtocolI2C *) super;
    // this->i2c->init(this->i2c);
}


static void OLEDProtocolI2C_write_(const OLEDProtocol *super,
                                   uint8_t salveAddress, uint16_t regAddress, uint8_t *dat, uint8_t len) {
    const OLEDProtocolI2C *this = (OLEDProtocolI2C *)super;
    I2C_send(this->i2c, salveAddress, regAddress, dat, len);
}

void OLEDProtocolI2C_constructor(OLEDProtocolI2C *this, I2C *i2c) {
    static struct OLEDProtocolVtbl vtbl = {
        .init = &OLEDProtocolI2C_init_,
        .write = &OLEDProtocolI2C_write_
    };
    OLEDProtocol_constructor(&this->oledProtocol);

    this->oledProtocol.vptr = &vtbl;
    this->i2c = i2c;
}
